package com.hongying.producer;

import com.hongying.constant.RabbitMqConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class DirectSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void send(){
        String now = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());

        String context = "Direct Message. " + now;
        this.rabbitTemplate.convertAndSend(RabbitMqConstant.DIRECT_EXCHANGE,RabbitMqConstant.DIRECT_ROUTING_KEY,context);
    }

}
